#ifndef _OCPP_ObliqueUtil_H_
#define _OCPP_ObliqueUtil_H_

#include "ObliqueNodeInfo.h"
#include "ObliqueTile.h"

namespace OCPP
{
	namespace Cesium
	{
		class _Osg2CesiumExport ObliqueUtil
		{
		public:
			ObliqueUtil() {}

			static void writePreview(StringVector& tiles, String dataPath);
		};

		inline osg::BoundingBox str2box(String& boundingBoxStr)
		{
			osg::BoundingBox boundingBox;
			StringVector sv = StringUtil::split(boundingBoxStr);
			StringVector sv1 = StringUtil::split(sv[0], ",");
			StringVector sv2 = StringUtil::split(sv[1], ",");
			boundingBox.xMin() = std::stof(sv1[0]);
			boundingBox.yMin() = std::stof(sv1[1]);
			boundingBox.zMin() = std::stof(sv1[2]);
			boundingBox.xMax() = std::stof(sv2[0]);
			boundingBox.yMax() = std::stof(sv2[1]);
			boundingBox.zMax() = std::stof(sv2[2]);
			return boundingBox;
		}

		inline String box2string(osg::BoundingBox& bound)
		{
			if (!bound.valid()) return "0,0,0 0,0,0";
			return str_format("%.3f,%.3f,%.3f %.3f,%.3f,%.3f",
				bound.xMin(), bound.yMin(), bound.zMin(),
				bound.xMax(), bound.yMax(), bound.zMax());
		}

		inline String box2size(osg::BoundingBox& bound)
		{
			if (!bound.valid()) return "0,0,0";
			return str_format("%.3f,%.3f,%.3f",
				bound.xMax() - bound.xMin(), bound.yMax() - bound.yMin(), bound.zMax() - bound.zMin());
		}

		inline void writeJsonFile(Json::Value& jsonObj, String fileName)
		{
			Json::StreamWriterBuilder wbuilder;
			wbuilder.settings_["indentation"] = "   ";
			wbuilder.settings_["emitUTF8"] = true;
			String jsonStr = Json::writeString(wbuilder, jsonObj);
			std::ofstream ofs(fileName);
			ofs << A2U8(jsonStr);
			ofs.close();
		}

	}
}

#endif // !_OCPP_ObliqueUtil_H_
